@extends('layouts.home')
@extends('layouts.nav')
@extends('layouts.top')

@section('heading')
    <h3>
        账号设置
    </h3>
    <ul class="breadcrumb">
        <li>
            <a href="#">用户管理</a>
        </li>
        <li class="active"> 账号新增</li>
    </ul>
@endsection


@section('wrapper')
    <section class="panel">

        <div class="panel-body">
            <div class=" form">
                @if(isset($user))
                    <form method="POST" action="{{ route('users.update', $user->id) }}" class="cmxform form-horizontal adminex-form">
                        {{ method_field('PATCH') }}
                @else
                    <form method="POST" action="{{ route('users.store') }}" class="cmxform form-horizontal adminex-form">
                @endif
                    @csrf
                    <div class="form-group ">
                        <label for="cname" class="control-label col-lg-2">名称</label>
                        <div class="col-lg-10">
                            <input class=" form-control{{ $errors->has('name') ? ' error' : '' }}" id="cname" value="{{ $user->name or old('name') }}" name="name" minlength="2" type="text" required/>
                            @if ($errors->has('name'))
                                <label class="error">{{ $errors->first('name') }}</label>
                            @endif
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label col-lg-2" for="inputSuccess">角色</label>
                        <div class="col-lg-5">
                            <select class="form-control m-bot15" name="role_id">
                                <option value="">选择</option>
                                @foreach($roles as $role)
                                    @if(!empty($rolesUser))
                                        <option {{ $rolesUser == $role->name ? 'selected' : ''}} value="{{ $role->id }}">{{ $role->name }}</option>
                                    @else
                                        <option value="{{ $role->id }}">{{ $role->name }}</option>
                                    @endif
                                @endforeach
                            </select>
                        </div>
                        @if ($errors->has('role_id'))
                            <label class="error">{{ $errors->first('role_id') }}</label>
                        @endif
                    </div>
                    <div class="form-group ">
                        <label for="cemail" class="control-label col-lg-2">邮箱账号</label>
                        <div class="col-lg-10">
                            <input class="form-control{{ $errors->has('email') ? ' error' : '' }}" value="{{ $user->email or old('email') }}" id="cemail" type="email" name="email" required/>
                            @if ($errors->has('email'))
                                <label class="error">{{ $errors->first('email') }}</label>
                            @endif
                        </div>
                    </div>
                    <div class="form-group ">
                        <label for="ccomment" class="control-label col-lg-2">密码</label>
                        <div class="col-lg-10">
                            <input class="form-control " id="cemail" type="password" name="password" @if(!isset($user)) required @endif/>
                            @if ($errors->has('password'))
                                <label class="error">{{ $errors->first('password') }}</label>
                            @endif
                        </div>
                    </div>
                    <div class="form-group ">
                        <label for="ccomment" class="control-label col-lg-2">确认密码</label>
                        <div class="col-lg-10">
                            <input class="form-control " id="cemail" type="password" name="password_confirmation"
                                   @if(!isset($user)) required @endif/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-10">
                            <button class="btn btn-primary" type="submit">保存</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </section>
@endsection